cmake_minimum_required(VERSION 3.0.0)

add_executable(nconverter 
    main.c
    ${CMAKE_BINARY_DIR}/nconverter/nconverter_jar.o
)

target_link_libraries(nconverter log)


message(STATUS "ProjectDir:" ${CMAKE_SOURCE_DIR})
message(STATUS "BUILDDIR:" ${CMAKE_BINARY_DIR})

file(GLOB JAVA_SOURCE "${CMAKE_SOURCE_DIR}/nconverter/src/main/java/com/nconverter/*.java")
file(GLOB_RECURSE LIB_JAVA_SOURCE "${CMAKE_SOURCE_DIR}/library/src/main/java/com/dstukalov/videoconverter/*.java")

add_custom_command(
    OUTPUT ${CMAKE_SOURCE_DIR}/nconverter.jar
    COMMAND cd ${CMAKE_SOURCE_DIR}
    COMMAND ./gradlew  nconverter:assembleRelease
    COMMAND cp ${CMAKE_SOURCE_DIR}/nconverter/build/outputs/apk/release/nconverter-release-unsigned.apk  ${CMAKE_SOURCE_DIR}/nconverter.jar
    DEPENDS ${JAVA_SOURCE} ${LIB_JAVA_SOURCE}
)

add_custom_command(
    OUTPUT ${CMAKE_BINARY_DIR}/nconverter/nconverter_jar.o
    COMMAND cd ${CMAKE_SOURCE_DIR}
    COMMAND /mnt/old/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-objcopy -I binary -O elf64-aarch64 nconverter.jar nconverter_jar.o
    COMMAND mv nconverter_jar.o ${CMAKE_BINARY_DIR}/nconverter/
    #COMMAND /mnt/old/Android/Sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/linux-x86_64/bin/ld -r -b binary -o nconverter_jar.o nconverter.jar
    DEPENDS ${CMAKE_SOURCE_DIR}/nconverter.jar
)
